

#include "platform.h"

#include "config/parameter_group_ids.h"

#include "drivers/io.h"
#include "io_impl.h"

#include "light_led.h"

static IO_t leds[STATUS_LED_NUMBER];
static uint8_t ledInversion = 0;

void ledInit()
{
    ledInversion = 0;

    leds[0] = IOGetByTag(IO_TAG(LED0_PIN));
    IOInit(leds[0], OWNER_LED, RESOURCE_INDEX(0));
    IOConfigGPIO(leds[0], IOCFG_OUT_PP);

    leds[1] = IOGetByTag(IO_TAG(LED1_PIN));
    IOInit(leds[1], OWNER_LED, RESOURCE_INDEX(1));
    IOConfigGPIO(leds[1], IOCFG_OUT_PP);

    leds[2] = IOGetByTag(IO_TAG(LED2_PIN));
    IOInit(leds[2], OWNER_LED, RESOURCE_INDEX(2));
    IOConfigGPIO(leds[2], IOCFG_OUT_PP);
#ifdef LED3_PIN
    leds[3] = IOGetByTag(IO_TAG(LED3_PIN));
    IOInit(leds[3], OWNER_LED, RESOURCE_INDEX(3));
    IOConfigGPIO(leds[3], IOCFG_OUT_PP);
    LED3_OFF;
#endif
#ifdef LED4_PIN
    leds[4] = IOGetByTag(IO_TAG(LED4_PIN));
    IOInit(leds[4], OWNER_LED, RESOURCE_INDEX(4));
    IOConfigGPIO(leds[4], IOCFG_OUT_PP);
    LED4_OFF;
#endif
    LED0_OFF;
    LED1_OFF;
    LED2_OFF;
}

void ledToggle(int led)
{
    IOToggle(leds[led]);
}

void ledSet(int led, bool on)
{
    if(on){
        IOHi(leds[led]);
    }else{
        IOLo(leds[led]);
    }
}
